<a href="<?php echo $this->url(array(
    'controller' => 'courses',
    'action' => 'add'
)); ?>"><button class="btn btn-inverse"><?php echo $this->translate('Добавить новый курс')?></button></a><br><br>

<?php if (count($this->courses)): ?>
<table class="table table-bordered" >
    <thead>
        <tr>
            <th><?php echo $this->translate('Название курса')?></th>
            <th><?php echo $this->translate('Описание')?></th>
            <th><?php echo $this->translate('Предмет')?></th>
            <th><?php echo $this->translate('Рейтинг')?></th>
            <th><?php echo $this->translate('Действия')?></th>
        </tr>
    </thead>
    <tbody>
    <?php foreach ($this->courses as $item):?>
    <tr>
        <td width="20%"><a href="/courses/admin/id/<?php echo $item['course_id'] ?>">
            <h4><?php echo $this->escape($item['name']) ?></a></h4></td>
        <td width="50%"><h5 class="nobold"><?php echo $this->escape($item['description']); ?></h5></td>
        <td width="5%"><h5 class="nobold"> <?php
            $_dbTable = new Model_DbTable_Subjects();
            $select = $_dbTable->select();
            $select->where('subject_id = ?', $item['subject_id']);
            $_row = $_dbTable->fetchAll($select);
            foreach ($_row as $itemf){
                echo $itemf['name'];
            }
        ?></h5>
        </td>
        <td width="10%"> <h5 class="nobold"><center><?php 
            $_dbTableLec = new Model_DbTable_Lectures();
            $selectLec = $_dbTableLec->select();
            $selectLec->where('course_id = ?', $item['course_id']);
            $_rowLec = $_dbTableLec->fetchAll($selectLec);
            
            $sumV = 0;
            $sumC = 0;
            
            foreach ($_rowLec as $itemf){
                $sumV += $itemf['rank_value'];
                $sumC += $itemf['rank_count'];
            }
            if($sumC) echo round($sumV / $sumC, 1);
            else echo $this->translate('Оценок нет');
            ?></center></h5>
        </td>
        <td>
            <a class="btn btn-info" href ="
                <?php echo $this->url(array(
                'controller'=>'courses',
                'action'=>'admin',
                'id'=>$item['course_id'],
                )); ?>"><?php echo $this->translate('Просмотреть курс')?></a><br>

            <a class="btn btn-warning" 
               style="margin-top: 5px; width: 120px;" 
               href ="
               <?php echo $this->url(array(
                'controller'=>'courses',
                'action'=>'edit',
                'cid'=>$item['course_id'],
                )); ?>"><?php echo $this->translate('Редактировать')?></a><br>
       
            <a href="#myModal-<?php echo $item['course_id']; ?>" 
               role="button" class="btn btn-danger" 
               style="margin-top: 5px; width: 120px;" 
               data-toggle="modal"><?php echo $this->translate('Удалить')?></a>

            <div id="myModal-<?php echo $item['course_id']; ?>" class="modal hide fade" 
                 tabindex="-1" role="dialog" aria-labelledby="myModalLabel" aria-hidden="true">
            <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
            <h3 id="myModalLabel"><?php echo $this->translate('Удалить этот курс?')?></h3>
            </div>
            <div class="modal-body">
            <p><?php echo $this->translate('Потом вы не сможете отменить это действие.')?></p>
            </div>
            <div class="modal-footer">
            <button class="btn" data-dismiss="modal" aria-hidden="true">
                <?php echo $this->translate('Отмена')?></button>
            <a href="/courses/del/cid/<?php echo $item['course_id'] ?>" 
               class="btn btn-danger"><?php echo $this->translate('Удалить')?></a>
            </div>
            </div>
        </td>
    </tr>
<?php
    endforeach; ?>
    </tbody>
    </table>
<?php else:
?>
    <p><?php echo $this->translate('Вы еще не создали своих курсов.')?></p>
<?php endif ?>